<?php
/**
 * List Of medical studies
 *
 *
 */
use Nawa\Messages;
use Fox\Generator;
use Fox\Grid\FieldCat\Field\Renderer\Anchor;
use Fox\Html\Button;
use Nawa\Customer;
use Nawa\MedicalStudy;
use Fox\Html\Screen;

$id = Xview::instance()->val("customerid");
// Check Consistency
try {
	$customer = new Customer($id);
	$medicalStudies = $customer->medicalStudies();
	$nbMs = count($medicalStudies);
}
catch (Fox\Object\Exception\NotExist $e)
{
	Xview::instance()->systemError();
}
if(!$customer->exists())
{
	Xview::instance()->systemError();
}

$labelMS = Msg(Messages::BUNDLE,Messages::LABEL_STUDIES);
$screen = new Screen("sMedicalStudies");
$screen->breadcrumb()->crumb("?mod=customers&act=search","Promoteurs");
$screen->breadcrumb()->crumb("?mod=customers&act=update&customerid=$id",$customer->name1);
$screen->breadcrumb()->crumb("?mod=customers&act=medicalstudies&customerid=$id","$labelMS ($nbMs)",true);

$screen->mainTitle("<div class=\"page-title\" >$labelMS - $customer->name1 </div>");
$screen->toolbar()->add(new Button("create","?mod=medicalstudies&act=create&sourceid=$id"));

$grid = new Fox\Grid("gMedicalStudies");
$grid->fieldcat(array(array("ms_reference","reference"),"label","start_date","end_date"));
$grid->fieldcat()->switchToObjectMode();
$grid->fieldcat()->setFieldAttr('*', 'renderers',new Anchor(Generator::url(
	'medicalstudies',
	'update',
null,
array('msid' => Generator::useAttribute('msid'))
)));
$grid->initialize($medicalStudies,true);

echo $screen->display();
echo $grid->display();